function loadExtend(extendss, rfun) {
    var jss = {
        category: "/m/js/category.js",
        category_district: "/m/js/category_district.js",
        popform: "/m/js/bottlecms-popform.js?_d=2432331",
        plupload: "bc-application/Mobile/Assets/vendor/plupload/2.3.6/plupload.full.min.js?_d=243233444",
        jweixin: "https://res.wx.qq.com/open/js/jweixin-1.0.0.js",
        geolocation: "https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js",
        dialogue: "/m/js/dialogue.js"
    }
    //     , i = t.length;
    // for (var n in t) {
    //     var c = t[n];
    //     bottlecms.getJs(e[c], function () {
    //         if (i > 1)
    //             i--;
    //         else if (s)
    //             return s()
    //     })
    // }
    var num = extendss.length;
    for (var o in extendss) {
        var extend = extendss[o];
        bottlecms.getJs(jss[extend], function() {
            if (num > 1) {
                num--;
            } else {
                if (rfun) return rfun();
            }
        });
    }
}



// 定位
function getLocation(refun) {
    if (bottlecms.cookie('location')) {
        if (refun) return refun(bottlecms.cookie('location'));
    } else {
        var loadingobj = bottlecms.loading("定位中…<br>请开启手机定位，否则会定位失败～");
        //获取位置
        var geolocation = new qq.maps.Geolocation("2TNBZ-G6OH2-FQSUC-CMZOH-QUA2Z-2BBFI", "myapp");
        var positionNum = 0;
        $(function() { //定位
            geolocation.getLocation(function(position) {
                loadingobj.close();
                // window.console.log(position);
                var positionstr = JSON.stringify(position);
                bottlecms.cookie('location', positionstr, {
                    expires: 1440
                });
                if (refun) return refun(positionstr);
                return
            }, function() {
                loadingobj.close();
                bottlecms.toast("获取位置失败!");
            }, {
                timeout: 5000
            });
        })
    }
}

// 定位
function getLocation2(refun) {
    if (bottlecms.cookie('location') != null) {
        if (refun) return refun(bottlecms.cookie('location'));
    } else {
        var geolocation = new qq.maps.Geolocation("2TNBZ-G6OH2-FQSUC-CMZOH-QUA2Z-2BBFI", "myapp");
        var positionNum = 0;
        $(function () { //定位
            geolocation.getLocation(function (position) {
                var positionstr = JSON.stringify(position);
                if (positionstr != "") {
                    bottlecms.post("/ajax/position/setLocationCookie", {"value":positionstr});
                    if (refun) return refun(positionstr);
                }
                return false;
            },
            geolocation.getIpLocation(
                function (position) {
                    if (bottlecms.cookie('location') == null) {
                        var positionstr = JSON.stringify(position);
                        if (positionstr != "") {
                            bottlecms.post("/ajax/position/setLocationCookie", {"value":positionstr});
                            if (refun) return refun(positionstr);
                        }

                    }
                }
            ),
            function () {
                $('.radar_loading .tishi, .radar_loading .radar-box').hide();
                $('.radar_loading .fail').show();
                bottlecms.toast("获取位置失败!");
            }, {
                timeout: 5000
            });
        })
    }
}


//
// function getLocation(t, s) {
//     try {
//         debugger;
//         var e = new qq.maps.Geolocation("2TNBZ-G6OH2-FQSUC-CMZOH-QUA2Z-2BBFI", "myapp");
//         $(function () {
//             e.getLocation(function (s) {
//                 debugger;
//                 window.console.log(s);
//                 var e = JSON.stringify(s);
//                 return bottlecms.cookie("location", e, {
//                     expires: 1440
//                 }),
//                 !!t && t(e)
//             }, function () {
//                 return window.console.log("getLocation:err"),
//                 !!s && s()
//             }, {
//                 timeout: 5e3
//             })
//         })
//     } catch (t) {
//         return ""
//     }
// }

// loadExtend(["geolocation"], function () {
//     getLocation()
// });
// 定位
// function getLocation(refun) {
//     if (bottlecms.cookie('location')) {
//         if (refun) return refun(bottlecms.cookie('location'));
//     } else {
//         var loadingobj = bottlecms.loading("定位中…<br>请开启手机定位，否则会定位失败～");
//         //获取位置
//         var geolocation = new qq.maps.Geolocation("OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77", "myapp");
//         var positionNum = 0;
//         $(function () { //定位
//             geolocation.getLocation(function (position) {
//                 loadingobj.close();
//                 // window.console.log(position);
//                 var positionstr = JSON.stringify(position);
//                 bottlecms.cookie('location', positionstr, {
//                     expires: 1440
//                 });
//                 if (refun) return refun(positionstr);
//                 return
//             }, function () {
//                 loadingobj.close();
//                 bottlecms.toast("获取位置失败!");
//             }, {
//                 timeout: 5000
//             });
//         })
//     }
// }

/*======================================
                方法
=====================================*/
var system_notice = {};

//获取通知
function getNotice() {
    bottlecms.get('/m/ajax/center/notice/getSystemNotice', null, function (data) {
        system_notice = data.obj;
    }, function () {
    });
}

function showNotice() {
    for (var o in system_notice) {
        $("[bottlecms-notice='" + o + "']").text(system_notice[o]);
        system_notice[o] ? $("[bottlecms-notice='" + o + "']").removeClass('hide') : $("[bottlecms-notice='" + o + "']").addClass('hide');
    }
}

/*举报*/
function report_fun(target_id) {
    var afterText = '<div class="bcui-form js-pop-jubao" style="padding:0"><div class="form-item ub" style="margin-top:0"><select name="type" style="border-radius:3px"><option value="">选择举报类型</option><option value="1">虚假资料</option><option value="2">联系不上</option><option value="3">骗子</option><option value="4">其他</option></select></div><div class="form-item ub"><textarea  maxsize="150" name="content" placeholder="请填写举报原因～"></textarea></div></div>';
    bottlecms.confirm(afterText, function (modal, close) {
        var type = $(modal).find('select[name=type]').val();
        var content = $(modal).find('textarea[name=content]').val();
        bottlecms.post(BOTTLECMS_MOBILE_PATH + 'single/' + target_id + '/report', {
            type: type,
            content: content
        }, function (data) {
            if (data.success == true) {
                bottlecms.toast(data.msg);
                close();
            } else {
                bottlecms.toast(data.msg);
            }
        })
    })
}

/*分享*/
function share_fun() {
    $('body').append('<div class="sharepop" onClick="this.parentNode.removeChild(this)"></div>');
}

/*拉黑*/
function blacklist_fun(target_id, type, rfun) {
    var act = (type == 2) ? "unblacklist" : "blacklist";
    var text = (type == 2) ? "确定要把TA拉出黑明单吗?" : "确定要把TA拉黑吗?";
    bottlecms.confirm(text, function () {
        bottlecms.get(BOTTLECMS_MOBILE_PATH + 'single/' + target_id + '/' + act, null, function (data) {
            if (data.success == true) {
                bottlecms.toast(data.msg);
                if (rfun) return rfun();
            } else {
                bottlecms.toast(data.msg);
            }
        })
    });
}

/*心动*/

/*心动*/
function like_fun(target_id, type, rfun) {
    var act = (type == 2) ? "unlike" : "like";
    var userId = $("#userId").val();
    if (userId == undefined || userId == "") {
        userId = target_id;
    }
    bottlecms.get("/m/ajax/center/gift/like",
        {
            likeType: act,
            targetId: userId
        }
        , function (data) {
            if (data.success == true) {
                bottlecms.toast(data.msg);
                if (rfun) rfun();
            } else {
                bottlecms.toast(data.msg);
            }
        })
}

// function like_fun(t, s, e) {
// function like_fun(target_id, type, rfun) {
//     var likeType = 2 == type ? "unlike" : "like";
//     var userId = $("#userId").val();
//     if (userId == undefined || userId == "") {
//         userId = target_id;
//     }
//     bottlecms.get("/m/ajax/gift/like", {
//             likeType: likeType,
//             targetId: userId
//         },
//         function (t) {
//             1 == target_id.success ? (bottlecms.toast(target_id.msg), rfun && rfun()) : bottlecms.toast(target_id.msg)
//         })
// }

function gift_fun(t, s) {
    bottlecms.get("/m/ajax/center/gift/list", null,
        function (e) {
            if (1 == e.success && e.list && e.list.length > 0) {

                var i = '<div class="popup gift-pupup"><a href="#" class="close-pop close-popup">关闭</a>';
                i += '<div class="gifts">';
                for (var o in e.list) {
                    var v = e.list[o];

                    i += '<div class="item" data-id="' + v.id + '">';
                    i += '<div class="gift-cover"><img src="' + v.cover + '"/></div>';
                    i += '<div class="gift-name">' + v.title + '</div>';
                    i += '<div class="gift-price">' + (v.price > 0 ? v.price + bc_currency("currency_2", 'name') : "免费") + '</div>';
                    i += '</div>';
                    // if ((parseInt(o) + 1) % 8 == 0) {
                    //     popupHTML += '</li><li class="sw-slide gifts">';
                    // }
                }
                i += '</div>';
                i += '</div>';

                var o = bottlecms.modal({
                    content: i,
                    type: "conter"
                });
                $(o.thispop).find(".gift-pupup-swiper").swipeslider({
                    autoPlay: !1,
                    prevNextButtons: !1
                }),
                    $(o.thispop).find(".gifts .item[data-id]").click(function (e) {
                        var i = $(this).attr("data-id"),
                            n = $(this).find(".gift-cover img").attr("src"),
                            c = $(this).find(".gift-name").html();
                        o.close(),
                            bottlecms.confirm('确定要赠送TA此礼物吗？<div><img width="60" height="60" src="' + n + '"/><br><span style="font-size:.65rem;">' + c + "</span></div>",
                                function () {
                                    // bottlecms.get("/m/single/" + t + "/give_gift/" + i, null,

                                    bottlecms.get("/m/ajax/center/gift/give?userId=" + t + "&giftId=" + i, null,function (t) {
                                        if (t.success == true) {
                                            bottlecms.toast(t.msg);
                                            if (s){s();}
                                        } else {
                                            bottlecms.toast(data.msg);
                                        }
                                    })
                                })
                    })
            } else {
                bottlecms.toast(e.msg)
            }
        })
}

function pop_tip_pay_vip_candy(t) {
    var s = "";
    s += '<div class="pop_vip_candy" style="background:#FFF; width:280px;text-align: center;border-radius: 5px;">',
        s += '<div class="content" style="padding:20px;color:#F60;">' + (t = t || "你的套餐余量不足，升级VIP套餐或充值" + bc_currency("currency_2", "name") + "～") + "</div>",
        s += '<div class="btnbox"  style="padding:15px;"><a class="btn btn-sm btn-danger" href="/m/center/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="/m/center/account/deposit/cnady">购买' + bc_currency("currency_2", "name") + "</a></div>",
        s += "</div>",
        bottlecms.modal({
            content: s
        })
}

function pop_tip_pay_vip(t) {
    var s = "";
    s += '<div class="pop_vip_candy" style="background:#FFF; width:280px;text-align: center;border-radius: 5px;">',
        s += '<div class="content" style="padding:20px;color:#F60;">' + (t = t || "套餐余量不足，升级VIP套餐～") + "</div>",
        s += '<div class="btnbox"  style="padding:15px;"><a class="btn btn-sm btn-danger" href="/m/center/setmeal">升级VIP</a></div>',
        s += "</div>",
        bottlecms.modal({
            content: s
        })
}

function pop_tip_pay_candy(t) {
    var s = "";
    s += '<div class="pop_vip_candy" style="background:#FFF; width:280px;text-align: center;border-radius: 5px;">',
        s += '<div class="content" style="padding:20px;color:#F60;">' + (t = t || bc_currency("currency_2", "name") + "余额不足，充值" + bc_currency("currency_2", "name") + "～") + "</div>",
        s += '<div class="btnbox"  style="padding:15px;"><a class="btn btn-sm btn-info" href="/m/center/account/deposit/cnady">购买' + bc_currency("currency_2", "name") + "</a></div>",
        s += "</div>",
        bottlecms.modal({
            content: s
        })
}

function greet_send_fun(t, s, e) {
    if (s.greet_id == "") {
        bottlecms.toast("请选择招呼");
        return;
    }
    s.reconfirm = e,
        bottlecms.post(
            "/m/ajax/center/greet/send",
            {
                targetId: $("#userId").val(),
                id: s.greet_id
            },
            function (e) {
                if (1 == e.success) bottlecms.toast(e.msg);
                else {
                    if (202 == e.code) return pop_tip_pay_vip_candy(e.msg);
                    if (203 == e.code) return pop_tip_pay_vip(e.msg);
                    if (204 == e.code) return pop_tip_pay_candy(e.msg);
                    if (201 == e.code) {
                        var i = '<div style="color:#666;">您不是VIP会员或套餐余量不足<br />升级VIP套餐 或使用 <font color=#F60>' + e.obj.greet_fees + "</font> " + bc_currency("currency_2", "name") + "支付</div>";
                        i += '<div class="btnbox"  style="padding-top:19px;"><a class="btn btn-sm btn-danger" href="/m/center/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="/m/center/account/deposit/cnady">购买' + bc_currency("currency_2", "name") + "</a></div>",
                            bottlecms.confirm(i,
                                function () {
                                    return greet_send_fun(t, s, !0)
                                },
                                null, {
                                    confirm_text: bc_currency("currency_2", "name") + "支付"
                                })
                    } else bottlecms.toast(e.msg)
                }
            })
}

//批量打招呼
function greet_batch_fun() {
    bottlecms.get('/m/ajax/center/greet/matched', null, function (data) {
        if (data.success == true && data.list && data.list.length > 0) {
            var popupHTML = '';
            popupHTML += '<div class="greet_pop">';
            popupHTML += '    <div class="close close-pop" >×</div>';
            popupHTML += '    <div class="head">为你匹配</div>';
            popupHTML += '    <div class="lists">';
            for (var o in data.list) {
                var v = data.list[o];
                popupHTML += '        <div class="item active" data-id="' + v.userId + '">';
                popupHTML += '            <div class="photo"><img src="' + v.photo + '_200x200.jpg" /></div>';
                popupHTML += '            <div class="nickname ellipsis">' + v.nickname + '</div>';
                popupHTML += '            <i class="checkbox"></i>';
                popupHTML += '        </div>';
            }
            popupHTML += '    </div>';
            popupHTML += '    <div class="foot">';
            popupHTML += '        <button class="btn btn-sm js-btn">打招呼</button>';
            popupHTML += '    </div>';
            popupHTML += '</div>';
            var popup_modal = bottlecms.modal({
                content: popupHTML,
                type: 'content'
            });
            $(popup_modal.thispop).on('click', '.lists .item', function (e) {
                $(this).toggleClass('active');
            });
            $(popup_modal.thispop).on('click', '.js-btn', function () {
                var ids = [];
                $(this).parents(".greet_pop").find('.item.active').each(function (index, el) {
                    ids.push($(this).attr('data-id'));
                });
                greet_batch_send_fun(ids, {});
                popup_modal.close();
            });
        }
    })
}

//批量打招呼
function greet_batch_send_fun(target_ids, datas, reconfirm) {
    datas['reconfirm'] = reconfirm;
    datas['target_ids'] = target_ids;
    bottlecms.post('/m/ajax/center/greet/send', datas, function (data) {
        if (data.success == true) {
            bottlecms.toast(data.msg);
        } else if (data.code == 202) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip_candy(data.msg);
        } else if (data.code == 203) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip(data.msg);
        } else if (data.code == 204) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_candy(data.msg);
        }
        // 二次确认
        else if (data.code == 201) {
            var html = '<div style="color:#666;">套餐余量不足<br />升级VIP套餐 或使用 <font color=#F60>' + data.obj.greet_fees + '</font> ' + bc_currency("currency_2", 'name') + '支付，你还剩余 <font color=#F60>' + data.obj.candy + '</font> ' + bc_currency("currency_2", 'name') + '。</div>';
            html += '<div class="btnbox"  style="padding-top:19px;"><a class="btn btn-sm btn-danger" href="' + BOTTLECMS_MOBILE_PATH + 'manage/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="' + BOTTLECMS_MOBILE_PATH + 'manage/account/deposit/cnady">购买' + bc_currency("currency_2", 'name') + '</a></div>';
            bottlecms.confirm(html, function () {
                return greet_batch_send_fun(target_ids, datas, true);
            }, null, {
                confirm_text: '' + bc_currency("currency_2", 'name') + '支付'
            })
        } else {
            bottlecms.toast(data.msg);
        }
    });
}

function greet_fun(t) {
    bottlecms.get("/m/ajax/center/greet", null,
        function (s) {
            1 == s.success && s.obj && bottlecms.confirm("打招呼<div>" + s.obj + "</div>",
                function (s) {
                    var e = {};
                    return $(s).find("[name]").each(function (t, s) {
                        var i = $(this).attr("name"),
                            n = $(this).val();
                        e[i] = n,
                        "checkbox" == $(this).attr("type") && 1 != $(this).is(":checked") && delete e[i]
                    }),
                        greet_send_fun(t, e)
                })
        })
}

function updata_single_fun(t, s) {
    !t || !t.length < 1 || bottlecms.put("/m/ajax/center/single/modify", t,
        function (t) {
            1 == t.success ? s && s(t.obj) : bottlecms.toast(t.msg)
        })
}

function updata_single_photo_fun(t, s) {
    bottlecms.put("/m/ajax/center/photo", {
            photo: t
        },
        function (t) {
            1 == t.success ? s && s(t.obj) : bottlecms.toast(t.msg)
        })
}

function updata_user_photo_fun(t, s) {
    bottlecms.post("/m/ajax/center/photo", {
            photo: t
        },
        function (t) {
            1 == t.success ? (s && s(t), bottlecms.toast(t.msg)) : bottlecms.toast(t.msg)
        })
}

function delete_user_photo_fun(t, s) {
    bottlecms.delete("/m/ajax/center/photo", {
            id: t
        },
        function (t) {
            1 == t.success ? (s && s(t), bottlecms.toast(t.msg)) : bottlecms.toast(t.msg)
        })
}

function oauth_release_fun(t, s) {
    bottlecms.get("oauth/" + t + "/release", null,
        function (t) {
            1 == t.success ? (s && s(t), bottlecms.toast(t.msg)) : bottlecms.toast(t.msg)
        })
}

// 录音
function recorder_fun() {
    var popupHTML = '<div class="popup recorder_pop">';
    popupHTML += '<div class="titiles">最长60秒</div>';
    popupHTML += '<div class="progressbar"><div></div></div>';
    popupHTML += '<div class="btnbox"><button class="btn btn-sm btn-info js-recorder-btn">按住说话</button></div>';
    popupHTML += '<div class="rebtnbox" style="display: none;"><div class="speak"></div><button class="btn btn-sm  js-upload-btn">确认</button><button class="btn btn-sm btn-invalid js-reset-btn">重录</button></div>';
    popupHTML += '</div>';
    var popup_modal_obj = bottlecms.modal({
        content: popupHTML,
        type: 'bottom'
    });
    var popup_modal = popup_modal_obj.thispop;
    var timer;
    var time;
    var localId;
    var js_recorder_btn = $(popup_modal).find(".js-recorder-btn");
    var startRecord = function() {
        if ($(js_recorder_btn).hasClass('on')) {
            return stopRecord();
        }
        $(js_recorder_btn).addClass('on');
        wx.startRecord(); //开始录音
        clearInterval(timer);
        time = 59;
        var timei = 0;
        timer = setInterval(function() {
            if (time <= 0) {
                clearInterval(timer);
            } else {
                timei++;
                $(popup_modal).find('.progressbar div').width((timei / 60 * 100) + "%");
                $(popup_modal).find('.titiles').text('剩余' + time + '秒');
                time--;
            }
        }, 1000);
    }
    var stopRecord = function() {
        clearInterval(timer);
        if (!$(js_recorder_btn).hasClass('on')) {
            return;
        }
        $(js_recorder_btn).removeClass('on');
        if (time < 56) {
            $(popup_modal).find('.btnbox').hide();
            $(popup_modal).find('.rebtnbox').show();
        } else {
            bottlecms.toast("时间太短～")
        }
        wx.stopRecord({
            success: function(res) {
                localId = res.localId;
            },
            fail: function(res) {
                bottlecms.toast("录音失败");
                // alert("stopRecord:" + JSON.stringify(res));
            }
        });
    }
    // 开始录制
    $(js_recorder_btn).on('touchstart mousedown', function(e) {
        event.preventDefault();
        event.stopPropagation();
        // window.console.log("touchstart");
        startRecord();
    }).on('touchend touchcancel mouseup', function(e) {
        // window.console.log("touchend");
        stopRecord();
    });
    // 重录
    $(popup_modal).on('click', '.js-reset-btn', function(e) {
        $(popup_modal).find('.btnbox').show();
        $(popup_modal).find('.rebtnbox').hide();
        $(popup_modal).find('.titiles').text('最长60秒');
    });
    // 上传
    $(popup_modal).on('click', '.js-upload-btn', function(e) {
        var thisloading = bottlecms.loading("上传转码中…");
        popup_modal_obj.close();
        wx.uploadVoice({
            localId: localId, // 需要上传的音频的本地ID，由stopRecord接口获得
            isShowProgressTips: 1, // 默认为1，显示进度提示
            success: function(res) {
                var serverId = res.serverId; // 返回音频的服务器端ID
                // window.console.log(res)
                bottlecms.post("/m/ajax/wechat/loadFile", {
                    serverId: serverId
                }, function(data) {
                    thisloading.close();
                    if (data.success == true) {
                        updata_single_fun({
                            voice: data.obj
                        }, function(data) {
                            bottlecms.toast("上传成功");
                            window.location.href = window.location.href;
                        })
                    } else {
                        bottlecms.toast(data.msg);
                    }
                }, function(err) {
                    thisloading.close();
                    bottlecms.toast("转码失败！");
                })
            },
            fail: function(res) {
                thisloading.close();
                bottlecms.toast("转码失败～");
                // alert("uploadVoice:" + JSON.stringify(res));
            }
        });
    });
}

// 删除朋友
function delete_friend_fun(target_id, rfun) {
    bottlecms.confirm("确定要删除吗？", function() {
        bottlecms.delete(BOTTLECMS_MOBILE_PATH + "friend/" + target_id + "/delete", null, function(data) {
            if (data.success == true) {
                if (rfun) rfun(data);
                bottlecms.toast(data.msg);
            } else {
                bottlecms.toast(data.msg);
            }
        });
    })
}
// 删除聊天记录
function delete_chat_fun(target_id, rfun) {
    bottlecms.confirm("确定要删除吗？", function() {
        bottlecms.delete("/m/ajax/center/chat/delete?targetId=" + target_id , null, function(data) {
            if (data.success == true) {
                if (rfun) rfun(data);
                bottlecms.toast(data.msg);
                $("#chat_list").html("");
            } else {
                bottlecms.toast(data.msg);
            }
        });
    })
}

function apply_friend_fun(t, s, e) {
    bottlecms.get("/m/ajax/center/friend/apply/" + t, {
            reconfirm: e
        },
        function (e) {
            if (1 == e.success) return s && s(e),
                bottlecms.toast(e.msg);
            if (202 == e.code) return pop_tip_pay_vip_candy(e.msg);
            if (203 == e.code) return pop_tip_pay_vip(e.msg);
            if (204 == e.code) return pop_tip_pay_candy(e.msg);
            if (201 != e.code) return bottlecms.toast(e.msg);
            var i = '<div style="color:#666;">您不是VIP会员或套餐余量不足<br />升级VIP套餐 或使用 <font color=#F60>' + e.obj.friend_apply_fees + "</font> " + bc_currency("currency_2", "name") + "支付</div>";
            i += '<div class="btnbox"  style="padding-top:19px;"><a class="btn btn-sm btn-danger" href="/center/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="/m/center/account/deposit/cnady">购买' + bc_currency("currency_2", "name") + "</a></div>",
                bottlecms.confirm(i,
                    function () {
                        return apply_friend_fun(t, s, !0)
                    },
                    null, {
                        confirm_text: bc_currency("currency_2", "name") + "支付"
                    })
        })
}

function agree_apply_friend_fun(t, s) {
    bottlecms.get("/m/ajax/center/friend/agree/" + t, null,
        function (t) {
            return 1 == t.success ? (s && s(t), bottlecms.toast(t.msg)) : bottlecms.toast(t.msg)
        })
}

function refuse_apply_friend_fun(t, s) {
    bottlecms.get("/m/ajax/center/friend/refuse/" + t, null,
        function (t) {
            return 1 == t.success ? (s && s(t), bottlecms.toast(t.msg)) : bottlecms.toast(t.msg)
        })
}

function apply_contact_fun(t, s, e, i) {
    bottlecms.get("/m/ajax/center/contact/apply_contact?reviewUserId=" + t, {reconfirm: e},function (e) {
            if (1 == e.success) {
                var n = eval('(' + e.obj + ')'),
                    c = "";
                return c += '<div class="contactbox">',
                "wechat" == i && (n.wechatId || n.wechat_qrcode) && (n.wechat_qrcode && (c += '<div style="display:none" id="wechat_qrcode" ></div><img style="height:120px;" id="wechatqrcodeimg" />'), n.wechatId && (c += "<div>微信号：" + n.wechatId + "</div>")),
                "qq" == i && n.qq && (c += "<div>QQ：" + n.qq + "</div>"),
                "email" == i && n.email && (c += "<div>邮箱：" + n.email + "</div>"),
                "phone" == i && n.phone && (c += "<div>电话：" + n.phone + "</div>"),
                    c += "</div>",
                    bottlecms.confirm(c, null, null, {
                        cancel: !1,
                        cancel_text: "确定"
                    }),
                $("#wechat_qrcode").length > 0 && ($("#wechat_qrcode").qrcode({
                    render: "canvas",
                    width: 120,
                    height: 120,
                    text: n.wechat_qrcode
                }), $("#wechatqrcodeimg").attr("src", $("#wechat_qrcode").find("canvas").get(0).toDataURL("image/jpg"))),
                    void (s && s(e))
            }
            if (302 == e.code) return window.location.href = e.obj;
            if (202 == e.code) return pop_tip_pay_vip_candy(e.msg);
            if (203 == e.code) return pop_tip_pay_vip(e.msg);
            if (204 == e.code) return pop_tip_pay_candy(e.msg);
            if (201 == e.code) {
                c = '<div style="color:#666;">您不是VIP会员或套餐余量不足<br />升级VIP套餐 或使用 <font color=#F60>' + e.obj.contact_apply_fees + "</font> " + bc_currency("currency_2", "name") + "支付</div>";
                c += '<div class="btnbox"  style="padding-top:19px;"><a class="btn btn-sm btn-danger" href="/m/center/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="/m/center/account/deposit/cnady">购买' + bc_currency("currency_2", "name") + "</a></div>",
                    bottlecms.confirm(c,
                        function () {
                            return apply_contact_fun(t, s, !0)
                        },
                        null, {
                            confirm_text: bc_currency("currency_2", "name") + "支付"
                        })
            } else {
                if (209 != e.code) return bottlecms.toast(e.msg);
                bottlecms.confirm('<div style="color:#F60;padding:1rem 0;">' + e.msg + "</div>",
                    function () {
                        apply_friend_fun(t)
                    },
                    function () {
                        bottlecms.back()
                    },
                    {
                        confirm_text: "加好友",
                        cancel_text: "返回"
                    })
            }
        })
}

function agree_apply_contact_fun(t, s) {
    bottlecms.get("/m/ajax/center/contact/agree?id=" + t, null,
        function (t) {
            return 1 == t.success ? (s && s(t), bottlecms.toast(t.msg)) : bottlecms.toast(t.msg)
        })
}

function refuse_apply_contact_fun(t, s) {
    bottlecms.get("/m/ajax/center/contact/refuse?id=" + t, null,
        function (t) {
            return 1 == t.success ? (s && s(t), bottlecms.toast(t.msg)) : bottlecms.toast(t.msg)
        })
}

function popup_tips_photo() {
    bottlecms.modal({
        content: '<div><a href="/m/center/single/modify"><img style="display:block" width="250" height="325" src="' + bc_asset("bc-application/Mobile/Assets/Mobile/img/pop_verify_photo.png") + '" /></a></div>'
    })
}

function popup_tips_identity() {
    bottlecms.modal({
        content: '<div><a href="/m/center/auth/identity"><img style="display:block" width="250" height="325" src="' + bc_asset("bc-application/Mobile/Assets/Mobile/img/pop_verify_identity.png") + '" /></a></div>'
    })
}

function popup_tips_mobile() {
    bottlecms.modal({
        content: '<div><a href="/m/center/user_mobile"><img style="display:block" width="250" height="325" src="' + bc_asset("bc-application/Mobile/Assets/Mobile/img/pop_verify_mobile.png") + '" /></a></div>'
    })
}

function popup_tips_vip() {
    bottlecms.modal({
        content: '<div><a href="/m/center/setmeal"><img style="display:block" width="250" height="325" src="' + bc_asset("bc-application/Mobile/Assets/Mobile/img/pop_verify_vip.png") + '" /></a></div>'
    })
}

function singles_template(t) {
    var s = "";
    return s += '<div class="item">',
        s += '    <a href="/m/single/info"' + t.userId + '>',
        s += '        <div class="photo-pack">',
        s += '            <img class="photo" photo_mode="' + t.photoMode + '" src="' + t.photo + '"/>',
        s += '            <div class="location">',
        s += '                <i class="icon-location">',
        s += "                </i>",
        s += "                " + t.districtCn,
        s += "            </div>",
        s += "        </div>",
        s += '        <div class="info">',
        s += '            <div class="nickname">',
        s += "                " + t.nickname,
        s += '                <i class="icon gender_' + t.gender + '"></i>',
    1 == t.authIdentity && (s += '            <i class="icon_identity"></i>'),
        s += '                <i class="icon_usergroup icon_usergroup_' + t.groupId + '"></i>',
        s += "            </div>",
        s += '            <div class="otherinfo">',
        s += "                <span>" + t.age + "岁</span>",
    t.height && (s += "                <span> . </span>", s += "                <span>" + t.height + "cm</span>"),
    t.constellationCn && (s += "                <span> . </span>", s += "                <span>" + t.constellationCn + "</span>"),
    t.incomeCn && (s += "                <span> . </span>", s += "                <span>" + t.incomeCn + "</span>"),
        s += "            </div>",
        s += "        </div>",
        s += "    </a>",
        s += "</div>"
}

/*声音列表 模版*/
function voices_template(v) {
    var html = '';
    html += '<div class="item">';
    html += '    <div class="bcui_voice" style="">';
    html += '        <div class="bcui_voice_back"  photo_mode="' + v.photoMode + '" style="background-image:url(' + v.photo + '_200x200.jpg"></div>';
    html += '        <audio controls="controls" hidden="" id="voice_' + v.userId + '" preload="none" src="' + v.voice + '"></audio>';
    html += '        <div class="bcui_voice_btn"></div>';
    html += '    </div>';
    html += '    <a class="nickname ellipsis" href="/m/single/info/' + v.userId + '">';
    html += '         ' + v.nickname + '';
    html += '         <i class="icon gender_' + v.gender + '"></i>';
    if (v.authIdentity == 1) {
        html += '            <i class="icon_identity"></i>';
    }
    html += '                <i class="icon_usergroup icon_usergroup_' + v.groupId + '"></i>';

    html += '    </a>';
    html += '</div>';
    html += '</div>';
    return html;
}

/*视频列表 模版*/
function videos_template(v) {
    var html = '';
    html += '<div class="item">';
    html += '    <a class="nickname" href="/m/video/show?src=' + v.video + '">';
    html += '    <div class="bcui_video" style="">';
    html += '        <div class="bcui_video_back"  photo_mode="' + v.photoMode + '" style="background-image:url(' + v.photo + '_200x200.jpg"></div>';
    html += '        <video controls="controls" hidden="" id="video_' + v.userId + '" preload="none" src="' + v.video + '"></video>';
    html += '        <div class="bcui_video_btn"></div>';
    html += '    </div>';
    html += '    </a>';
    html += '    <a class="nickname ellipsis" href="/m/single/info/' + v.userId + '">';
    html += '         ' + v.nickname + '';
    html += '         <i class="icon gender_' + v.gender + '"></i>';
    if (v.authIdentity == 1) {
        html += '            <i class="icon_identity"></i>';
    }
    html += '                <i class="icon_usergroup icon_usergroup_' + v.groupId + '"></i>';

    html += '    </a>';
    html += '</div>';
    html += '</div>';
    return html;
}

// 黑名单
function blacklist_template(v) {
    if (!v.psingle) return false;
    var html = "";
    html += '<div class="item ub ub-ac">';
    html += '    <a   class="ub ub-f1 "  href="' + BOTTLECMS_MOBILE_PATH + 'single/' + v.psingle.user_id + '">';
    html += '    <div class="ub-img1"  photo_mode="' + v.psingle.photo_mode + '" style="background-image:url(' + v.psingle.photo_100 + ')"></div>';
    html += '    <div class="ub-f1 info">';
    html += '        <div class="nickname">' + v.psingle.nickname + ' <span class="gender_' + v.psingle.gender + '"></span></div>';
    html += '        <p class="info"> ';
    if (v.psingle.district_cn) {
        html += '            <span class="district">' + v.psingle.district_cn + '</span> ';
    }
    html += '            ' + v.psingle.age + '岁 ';
    if (v.psingle.height) {
        html += '            . ' + v.psingle.height + 'cm ';
    }
    if (v.psingle.constellation_val) {
        html += '            . ' + v.psingle.constellation_val + ' ';
    }
    html += '        </p>';
    html += '    </div>';
    html += '    </a>';
    html += '    <div class="btnbox _dc">';
    html += '       <span class="btn btn-sm btn-info js_quxiao" data-id="' + v.psingle.user_id + '">拉出</span>';
    html += '    </div>';
    html += '</div>';
    return html;
}

function userlist_template(t) {
    var s = "";
    return s += '<div class="item ub ub-ac">',
        s += '    <a class="ub ub-f1 "  href="/m/single/info/"' + t.userId + '">',
        s += '    <div class="ub-img1"  photo_mode="' + t.photoMode + '" style="background-image:url(' + t.photo + '_200x200.jpg)"></div>',
        s += '    <div class="ub-f1 info">',
        s += '        <div class="nickname">' + t.nickname + ' <span class="gender_' + t.gender + '"></span></div>',
        s += '        <p class="info">',
    t.districtCn && (s += '           <span class="district">' + t.districtCn + "</span>"),
        s += '           <span class="age">' + t.age + "岁</span>",
    t.height && (s += '           . <span class="height">' + t.height + "cm</span>"),
    t.constellation && (s += '           . <span class="constellation">' + t.constellation + "</span>"),
    t.createTime && (s += '           <br><span class="created_at">' + t.createTime + "</span>"),
        s += "        </p>",
        s += "    </div>",
        s += "    </a>",
        s += "</div>"
}

function chat_template(t) {
    var s = "";
    return s += '<div class="item" data-uid="' + t.userId + '">',
        s += '<div class="picbox"><img class="pic" src="' + t.photo + '_200x200.jpg"></div>',
        s += '<div class="uinfo"><div class="nickname">' + t.nickname + '</div><div class="conversation">' + t.msgTitle + "</div></div>",
        s += '<div class="etime">' + t.createTime + "</div>",
    t.unreadNum > 0 && (s += '<div class="unreadNum">' + t.unreadNum + "</div>"),
        s += '<div class="editbox"><div class="_cp del" data-uid="' + t.userId + '">删除</div></div>',
        s += "</div>"
}

/*朋友列表*/
function friend_template(v) {
    var html = "";
    html += '<div class="item" data-uid="' + v.userId + '">';
    html += '<div class="picbox"><img  photo_mode="' + v.photoMode + '" src="' + v.photo + '_200x200.jpg"></div>';
    html += '<div class="uinfo"><div class="nickname">' + v.nickname + '</div></div>';
    // html+='<div class="toolbar"><div>查看资料</div><div>删除好友</div></div>';
    html += '</div>';
    return html;
}

/*新朋友列表*/
function friend_apply_template(v) {
    var html = "";
    html += '<div class="item ub ub-ac" status="' + v.isAuth + '">';
    html += '    <a   class="ub ub-f1 "  href="/m/single/info/' + v.userId + '">';
    html += '    <div class="ub-img1"  photo_mode="' + v.photoMode + '" style="background-image:url(' + v.photo + '_200x200.jpg)"></div>';
    html += '    <div class="ub-f1 info">';
    html += '        <div class="nickname">' + v.nickname + ' <span class="gender_' + v.gender + '"></span></div>';
    html += '        <p class="info"> ';
    if (v.districtCn) {
        html += '<span class="district">' + v.districtCn + '</span> ';
    }
    html += '' + v.age + '岁 ';
    if (v.height) {
        html += ' . ' + v.height + 'cm ';
    }
    if (v.constellationCn) {
        html += '. ' + v.constellationCn + '';
    }
    html += '        </p>';
    html += '    </div>';
    html += '    </a>';
    html += '    <div class="btnbox _dc">';
    html += '       <div class="status_3 group-btn group-btn-sm">';
    html += '           <span class="btn btn-info js_agree" data-id="' + v.userId + '">同意</span>';
    html += '           <span class="btn btn-danger js_refuse" data-id="' + v.userId + '">拒绝</span>';
    html += '       </div>';
    html += '       <div class="status_1">已同意</div>';
    html += '       <div class="status_2">已拒绝</div>';
    html += '       <div class="status_4">已超时</div>';
    html += '    </div>';
    html += '</div>';
    return html;
}

function contact_apply_template(t, s) {
    var arr = new Array();
    arr.push("<div class=\"item ub ub-ac\" status=\"" + t.agree + "\">");
    if (t.single) {
        //无信息
        arr.push("<a   class=\"ub ub-f1 \" href='/m/single/info/" + t.single.userId + "'>");
        arr.push("<div class=\"ub-img1\"  photo_mode=\"" + t.single.photoMode + "\" style=\"background-image:url(" + t.single.photo + "_200x200.jpg)\"></div>")
        arr.push(" <div class=\"ub-f1 info\">");
        arr.push("<div class=\"nickname\">" + t.single.nickname + "<span class=\"gender_" + t.single.gender + "\"></span></div>")
        arr.push("<p class=\"info\">");
        arr.push("<span class=\"district\">" + t.single.districtCn + "</span>");
        var age = t.single.age == null ? 19 : t.single.age;
        arr.push(age + "岁 . ");
        arr.push(t.single.height + "cm ");
        arr.push(t.single.constellationCn);
        arr.push("</p></div> </a>");
    } else {
        arr.push("<div  class=\"ub ub-f1 empty\">用户不存在或已删除</div>");
    }
    arr.push("<div class=\"btnbox _dc\">");
    if (s && t.agree == 3) {
        arr.push("<div class=\"status_3 group-btn group-btn-sm\">");
        arr.push("<span class=\"btn btn-info js_agree\" data-id=\"" + t.id + "\">同意</span>");
        arr.push(" <span class=\"btn btn-danger js_refuse\" data-id=\"" + t.id + "\">拒绝</span>");
        arr.push(" </div>");
    } else {
        if (t.agree == 3) {
            arr.push("<div class=\"status_3\">等待同意</div>");
        } else if (t.agree == 1) {
            arr.push("<div class=\"status_1\">已同意</div>");
        } else if (t.agree == 2) {
            arr.push("<div class=\"status_2\">已拒绝</div>");
        } else if (t.agree == 4) {
            arr.push("<div class=\"status_4\">已超时</div>");
        }
    }
    arr.push("</div></div>");
    return arr.join("");
}

function details_template(t) {

    var currencyName="喜糖";
    var currencyUnit="颗";
    if (t.currencyType==1){
        currencyName="现金";
        currencyUnit="元";
    }
    return '<div class="item ub"><div class="ub-f1">【' +currencyName+ "】" + t.remark + '<br><span class="info">' + t.createTime + '</span></div><div class="sr"><span>' + t.income + currencyUnit + "</span></div></div>"
}

function acticle_template(t) {
    var s = "";
    return s += '<div class="item"><div class="ub ub-ac">',
        s += '    <a   class="ub ub-f1 "  href="/m/article/info/' + t.id + ' ">',
        s += '    <div class="ub-img1" style="background-image:url(' + t.cover + ')"></div>',
        s += '    <div class="ub-f1 info">',
        s += '        <div class="item-title ellipsis">' + t.title + "</div>",
        s += '        <p class="info ellipsis2">' + t.summary + "</p>",
        s += "    </div>",
        s += "    </a>",
        s += "</div></div>"
}

function nearby_template(t) {
    var s = "";
    return s += '<div class="item"><div class="ub ub-ac">',
        s += '    <a   class="ub ub-f1 "  href="/m/single/info/"' + t.userId + '">',
        s += '    <div class="ub-img1"  photo_mode="' + t.photoMode + '" style="background-image:url(' + t.photo + '_200x200.jpg)"></div>',
        s += '    <div class="ub-f1 info">',
        s += '    <div class="nickname ellipsis">',
        s += "      " + t.nickname,
        s += '      <i class="icon gender_' + t.gender + '"></i>',
    1 == t.authIdentity && (s += '  <i class="icon_identity"></i>'),
        s += '      <i class="icon_usergroup icon_usergroup_' + t.group_id + '"></i>',
        s += "    </div>",
        s += '        <p class="info"> ',
        s += "            " + t.age + "岁 ",
    t.height && (s += "            . " + t.height + "cm "),
    t.constellationCn && (s += "            . " + t.constellationCn + " "),
        s += "        </p>",
        s += "    </div>",
        s += '    <div class="distance">距离<br><span>' + t.distance + "km</span></div>",
        s += "    </a>",
        s += "</div></div>"
}

/*缘分*/
function karma_template(index, v) {
    if (!v || !v.userId) return "";
    var html = "";
    html += '<div class="karma_ind karma_ind-' + index + '" id="karma_ind-' + index + '">';
    html += '<div class="itembox js-item" data-id="' + v.userId + '">';
    html += '<div class="userinfobox">';
    html += '<div class="photobox">';
    html += '   <img  photo_mode="' + v.photoMode + '" src="' + v.photo + '_600x600.jpg"/>';
    if (v.districtCn) {
        html += '   <div class="local">' + v.districtCn + '<br></div>';
    }
    html += '</div>';
    if (v.user_id) {
        html += '<div class="userinfo">';

        html += '   <div class="nickname ellipsis">';
        html += '      ' + v.nickname + '';
        html += '      <i class="icon gender_' + v.gender + '"></i>';

        if (v.authIdentity == 1) {
            html += '  <i class="icon_identity"></i>';
        }
        html += '      <i class="icon_usergroup icon_usergroup_' + v.groupId + '"></i>';

        html += '   </div>';

        html += '   <div class="info ellipsis3"> ';
        html += '            ' + v.age + '岁 ';
        if (v.height) {
            html += '            . ' + v.height + 'cm ';
        }
        if (v.constellationCn) {
            html += '            . ' + v.constellationCn + ' ';
        }
        html += '   </div> ';
        html += '</div> ';
    }
    html += '</div>';
    html += '<div class="botbtnbox">  ';
    html += '   <span class="buxihuan js-nolike" data-id="' + v.userId + '"></span>';
    html += '   <span class="xihuan js-like ' + (v.islike ? "on" : "") + '" data-id="' + v.userId + '"></span>';
    html += '</div>';
    html += '</div>';
    html += '</div>';
    return html;
}

// getNotice()
// setInterval(function () {
//     getNotice();
// }, 10000);
// setInterval(function () {
//     showNotice();
// }, 1000);

// 错误记录上报
// function errlog_fun(err) {
//     bottlecms.log(err);
// }



$("[data-href]").click(function(e) {
    window.location.href = $(this).data("href")
});

$(document).ready(function() {
    if ($("img[lay-src]").length > 0) {
        layui.flow.lazyimg("img[lay-src]");
    }
});


// 联动
layui.form.on('select', function(data){
    var areaId=data.elem.value;
    var o = $(this).parents('.layui-form-select').prev('select[bottlecms-mulselect]');
    if(o.length<=0){
        return;
    }
    var uuid = $(o).attr('seluuid');
    var index = parseInt($(o).attr('selindex'));
    var sel = $('select[seluuid="' + uuid + '"]');
    var table = $(o).attr('bottlecms-mulselect');

    sel.each(function() {
        var ind = parseInt($(this).attr('selindex'));
        if (ind <= index) {
            sel = sel.not($(this));
            return;
        }
        $(this).find('option').each(function(i) {
            if (i > 0) {
                $(this).remove();
            }
        });
    });
    $(o).data('lastval', areaId);
    if(!areaId){
        sel.eq(0).find().eq(0).nextAll().remove();
        layui.form.render('select');
        return;
    }

    bottlecms.get('/ajax/select/'+table+'/' + areaId, null, function(m) {
        var m = m.list;
        if (m && m.length > 2) {
            for (var i = 0; i < m.length; i++) {
                sel.eq(0).append('<option value="' + m[i].id + '">' + m[i].name + '</option>');
            }
            layui.form.render('select');
        }
    });
});

$(document).ready(function() {
    if($(".bcui-widget-slider").length>0){
        $(".bcui-widget-slider").owlCarousel({
            loop:true,
            responsiveClass:true,
            nav:true,
            dots:false,
            navText:[
                '<i class="fa fa-angle-left"></i>',
                '<i class="fa fa-angle-right"></i>'
            ],
            margin:30,
            autoplay:false,
            autoplayTimeout:2000,
            autoplayHoverPause:true,
            smartSpeed:2000,
            center:true,
            responsive:{
                0:{items:1,}
            }
        });
    }
});